package nr.nodehost;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;

import java.io.IOException;

@EnableAsync
@SpringBootApplication
@MapperScan("nr.nodehost.mapper")
public class NodeHostApplication {

	public static Logger log = LoggerFactory.getLogger(NodeHostApplication.class);
	//public static Dispatcher dispatcher;//=new Dispatcher();
	public static ConfigurableApplicationContext ac;
	
    public static void main(String[] args) throws IOException, InterruptedException {
    	log.info("NodeHostApplication started");
        ac=SpringApplication.run(NodeHostApplication.class, args);

        Listener listener=ac.getBean(Listener.class);
        NodeHostListener nodeHostListener = ac.getBean(NodeHostListener.class);
        ResourceGetter resourceGetter= ac.getBean(ResourceGetter.class);
        // todo 这里是启动一个线程，用于监听其他节点的消息，根据需要修改这里异步线程的名字
        resourceGetter.test();
        listener.start();
        nodeHostListener.run();
    }

}
